<?php
namespace app\admin\controller;
use think\Controller;
class Notice extends Common
{
	//公告显示
	public function index(){
		$data = db('Notice')->order('id desc')->paginate(15); 
		$this->assign('data',$data);
		return $this->fetch();
	}

	//添加公告
	public function add(){
		return $this->fetch();
	}

	//添加公告内容设置
	public function adds(){
		if(request() -> isPost()){
			$data = model('Notice')->adds();
			if($data['code']){
				$this->success($data['msg'],'admin/notice/index','',1);
			}else{
				$this->error($data['msg']);
			}
		}else{
            $this->error('请求失败');
		}
	}

	//编辑公告
	public function edit(){
		$id = input('param.id');
		$notice = db('notice')->where('id',$id)->find();
		$this->assign('notice',$notice);
		return $this->fetch();
	}

	//编辑公告内容
	public function edits(){
		if(request() -> isPost()){
            $data = model('Notice')->edits();
            if($data['code']){
            	$this->success($data['msg'],'admin/notice/index','',1);
            }else{
            	$this->error($data['msg']);
            }
		}else{
			$this->error('请求失败');
		}
	}

	//删除公告
	public function del(){
		$id = input('param.id');
		$del = db('notice')->where('id',$id)->delete();
		if($del > 0){
			$content = '删除公告';
	        admin_log($content); 
	        $this->success('删除成功','index','',1);
		}else{
			$this->error('删除失败');
		}
	}
}
